package com.jfree.nettyshow.common;

import com.jfree.nettyshow.inter.TaskHandler;
import org.springframework.util.StringUtils;

import java.util.Map;

public class HandlerManager {

    private Map<String, TaskHandler> handlerMap;//目前不支持动态修改handler,这里会传hashmap

    public HandlerManager(Map<String, TaskHandler> map) {
        this.handlerMap = map;
    }


    public TaskHandler getHandler(String version, String actionType) {
        if (StringUtils.isEmpty(version) || StringUtils.isEmpty(actionType)) {
            return null;
        }
        String key = getKey(version, actionType);
        return handlerMap.get(key);
    }

    public static String getKey(String version, String actionType) {
        if (StringUtils.isEmpty(version) || StringUtils.isEmpty(actionType)) {
            return null;
        }
        return version + version.hashCode() + "--" + actionType.hashCode() + actionType;
    }
}
